Skip to main content

All Questions

0votes
3answers
754views

Why isn't a counter used to avoid nested for loops for index based operations?

Let's assume we have a method that we want to run as fast as possible and it needs to loop on a 2D array, naturally we would do a nested for loop as such: int[][] arr = new int[3][3]; for(int ...
Yoh's user avatar
  • 51
3votes
3answers
1kviews

randomly filling in empty spaces in a matrix - O(N) amortized time?

Here are two ways to answer the following question. I'm trying to confirm what I believe their time complexity to be: If I had a snake game with a x,y matrix of spaces, some of which were occupied ...
max pleaner's user avatar
5votes
2answers
6kviews

Can "sub-linear" still be a straight line?

I'm working on a problem that requires a "sub-linear" solution. A quick search for sub-linear will return a lot of this... ... where the sub-linear line is modelled as logarithmic/asymptotic. But I ...
Birrel's user avatar
9votes
4answers
11kviews

Big-O for nested loop

I am reading this post on Big-O It says that the following code is O(n^2): bool ContainsDuplicates(String[] strings) { for(int i = 0; i < strings.Length; i++) { for(int j = 0; j &...
user10326's user avatar

close